package razor.blade;

import javafx.beans.binding.*;
import javafx.scene.*;
import javafx.beans.property.*;
import javafx.beans.value.*;
import javafx.scene.image.*;
import tee.binding.*;
public class TowLeftRight {
    private Numeric x;
    private Numeric y;
    private Numeric height;
    private Group root;
    //private TowLeftRight me;
    public Node node() {
        return root;
    }
    
    public TowLeftRight x(double it) {
	x.value(it);
	return this;
    }
    public TowLeftRight x(int it) {
	x.value(it);
	return this;
    }
    public Numeric x() {
	return x;
    }
    public TowLeftRight x(It<Double> it) {
	x.bind(it);
	return this;
    }
    public TowLeftRight y(double it) {
	y.value(it);
	return this;
    }
    public TowLeftRight y(int it) {
	y.value(it);
	return this;
    }
    public Numeric y() {
	return y;
    }
    public TowLeftRight y(It<Double> it) {
	y.bind(it);
	return this;
    }
    
    public TowLeftRight height(double it) {
	height.value(it);
	return this;
    }
    public TowLeftRight height(int it) {
	height.value(it);
	return this;
    }
    public Numeric height() {
	return height;
    }
    public TowLeftRight height(It<Double> it) {
	height.bind(it);
	return this;
    }
    
    
    
    /*public TowLeftRight x(double it) {
        x.set(it);
        return this;
    }
    public TowLeftRight x(int it) {
        x.set(it);
        return this;
    }
    public TowLeftRight x(SimpleDoubleProperty it) {
        x.bindBidirectional(it);
        return this;
    }
    public TowLeftRight x(DoubleBinding nn) {
        nn.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                x(newValue.doubleValue());
            }
        });
        x(nn.get());
        return this;
    }
    public TowLeftRight y(double it) {
        y.set(it);
        return this;
    }
    public TowLeftRight y(int it) {
        y.set(it);
        return this;
    }
    public TowLeftRight y(SimpleDoubleProperty it) {
        y.bindBidirectional(it);
        return this;
    }
    public TowLeftRight y(DoubleBinding nn) {
        nn.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                y(newValue.doubleValue());
            }
        });
        y(nn.get());
        return this;
    }
    public TowLeftRight height(double it) {
        height.set(it);
        return this;
    }
    public TowLeftRight height(int it) {
        height.set(it);
        return this;
    }
    public TowLeftRight height(SimpleDoubleProperty it) {
        height.bindBidirectional(it);
        return this;
    }
    public TowLeftRight height(DoubleBinding nn) {
        nn.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                height(newValue.doubleValue());
            }
        });
        height(nn.get());
        return this;
    }*/
    public TowLeftRight() {
        //me=this;
        x = new Numeric().value(0);
        y = new Numeric().value(0);
        height = new Numeric().value(100);
        root = new Group();
        root.getChildren().add(new ScrapeVertical()
                .x(x)
                .y(y)
                .height(height)
                .node());
        ImageView view = new ImageView();
        view.setImage(new Image(this.getClass().getResourceAsStream("steelVertical.png")));
        //view.xProperty().bind(x.subtract(8));
        //view.yProperty().bind(height.divide(2).subtract(47/2).add(y));
        root.getChildren().add(view);
	//final Numeric towY=new Numeric();
	/*final It<Double> cc=new Numeric().bind(height.divide(2).minus(47/2).plus(y));
	cc.afterChange(new Task(){
	    @Override public void doTask() {
		//System.out.println("cc: "+cc.value());
	    }
	});*/
	//cc.value(1000.0);
	//cc.value(2000.0);
	//System.out.println(tee.binding.About.getVersion());
        
        final Tow tow=new Tow();
        root.getChildren().add(tow
                .onShift(new Task(){@Override public void doTask() {
                        tow.x().value(tow.shiftX().value());
                        }
                    })
                .content(view)
                .x(x.minus(8))
                .y(height.divide(2).minus(47/2).plus(y))//.read())
                .cursor(Cursor.H_RESIZE)
                .node());
    }
}
